package com.example.myapplication.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.example.myapplication.R
import com.example.myapplication.databinding.ActivityCropBinding
import com.example.myapplication.ucrop.GlideEngine
import com.example.myapplication.ucrop.PictureCropSelectorActivity
import com.luck.picture.lib.PictureSelectionModel
import com.luck.picture.lib.PictureSelector
import com.luck.picture.lib.config.PictureMimeType
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.listener.OnResultCallbackListener


/**
 * @author: rongfeng
 * @date: 2022/3/10
 * @description
 */
class CropActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding: ActivityCropBinding = DataBindingUtil.setContentView(
            this, R.layout.activity_crop)
        binding.btnOpen.setOnClickListener {
            val selector: PictureSelectionModel =
                PictureSelector.create(this).openGallery(PictureMimeType.ofImage())
                    .isCompress(true)
                    //小于多少kb的图片不压缩
                    .minimumCompressSize(80)
                    .cutOutQuality(80)
                    .isPreviewImage(true)
                    .isZoomAnim(false)
                    .isCamera(false)
                    .isEnableCrop(true)
                    .maxSelectNum(1)
                    .minSelectNum(1)
                    .cropImageWideHigh(
                        300,
                        300
                    )
                    .withAspectRatio(
                        1,
                        1
                    )
                    .cutOutQuality(80)
                    .freeStyleCropEnabled(false)
                    .circleDimmedLayer(false)

            selector.selectionMode(1)
            selector.imageSpanCount(4)
            selector.isSingleDirectReturn(true)
            selector.imageEngine(GlideEngine.createGlideEngine())

            PictureCropSelectorActivity.forResult(object :
                OnResultCallbackListener<LocalMedia> {
                override fun onResult(result: MutableList<LocalMedia>?) {

                }

                override fun onCancel() {

                }
            }, this)


        }
    }


}